package com.lehoon.tomato.service.impl;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.lehoon.tomato.constant.WeChatConst;
import com.lehoon.tomato.model.wechat.WxAuthCodeMessage;
import com.lehoon.tomato.service.WeChatService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class WeChatServiceImpl implements WeChatService {

    @Override
    public WxAuthCodeMessage checkCode2Seesion(String code) {
        Map<String,Object> param = new HashMap<>();
        param.put("appid", WeChatConst.APP_ID);
        param.put("secret",WeChatConst.APP_SECRET);
        param.put("js_code",code);
        param.put("grant_type","authorization_code");
        String result = HttpUtil.get(WeChatConst.CODE2SESSION_URL,param);
        WxAuthCodeMessage message = JSONObject.parseObject(result,WxAuthCodeMessage.class);
        return message;
    }
}
